#ifndef xpack_lang_cxx_remove
#define xpack_lang_cxx_remove
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::lang_cxx::inc
#include"define/base_type.hpp"
#include"lang/cxx.hpp"
// #include"macro/xdebug_fail.hpp"
#include"macro/xunlikely.hpp"
#include"memop/copy.hpp"
#pragma pop_macro("xuser")

namespace mixc::lang_cxx{
    template<class item_t, inc::can_interval interval_t>
    inline void remove_core(auto self, interval_t range, auto const & alloc){
        xunlikely(range.normalize(self->length) == bstate_t::fail){
            return;
        }

        auto left           = uxx(range->left);
        auto right          = uxx(range->right);
        auto len            = self->length - (right - left + 1);

        xunlikely(left > right){
            // xdebug_fail(left > right);
            return;
        }

        auto stream         = alloc(len);

        xunlikely(stream == nullptr){
            return;
        }

        // 在 [left, right] 范围内的字符串都移除掉
        auto ptr            = (item_t *)self;
        stream.output(ptr, left);
        stream.output(ptr + right + 1, len - left);
    }

    template<class item_t>
    template<inc::can_interval interval_t, class xalloc_t, class ret_t, class>
    inline ret_t cxx<item_t>::remove(interval_t range, xalloc_t const & alloc) const {
        auto result         = the_t{};
        auto allocx         = the_t::helper::stream_helper(alloc, xmodify(result.m_ptr), xmodify(result.m_length));
        remove_core<item_t>(xthe, range, allocx);

        if constexpr (inc::is_same<ret_t, the_t>){
            return result;
        }
    }
}

#endif
